package lwf.db.manager;


import net.lwf.hibernate.dao.AppHitDAO;
import net.lwf.hibernate.dao.UserDAO;
import net.lwf.hibernate.entity.User;

import org.jasypt.util.password.BasicPasswordEncryptor;
import org.jasypt.util.password.PasswordEncryptor;

public class UserManager {
	
	
  public User getUser(String userid, String password) {
		User user = null;
		if(userid != null && password != null) {
			UserDAO dao = new UserDAO();
			user = dao.getUser(userid);
			if(user != null) {
		        PasswordEncryptor encryptor = new BasicPasswordEncryptor();
		        if(encryptor.checkPassword(password, user.getPassword()) && user.getUserStatus().equals("ACTIVE")) {
		        	user.setValid(true);
		        }
			}
		}
		return user;
	}
	
/*	public User getUser(String userid, String password) {
		User user = null;
		if(userid != null && password != null) {
			UserDAO dao = new UserDAO();
			user = dao.getUser(userid);
			if(user != null) {
		        if(LwfSecurity.getInstance().checkPassword(password, user.getPassword()) && 
		           user.getUserStatus().equals("ACTIVE")) {
		        	user.setValid(true);
		        }
			}
		}
		return user;
	}*/
	
	public void logHit(long counter) {
		AppHitDAO dao = new AppHitDAO();
		dao.logHit(counter);
	}

}
